﻿using Aker.DevTeam;
using DevTeam;
using Extensions;
using System;
using System.Data;
using System.Windows.Forms;

namespace Aker.Uretim
{
    public partial class ImalatCikis : XForm
    {
        int ProductId;
        public ImalatCikis(int ProductId)
        {
            InitializeComponent();
            this.ProductId = ProductId;
        }

        DataSet ds = null;

        private void ImalatCikis_Load(object sender, EventArgs e)
        {
            Bind();
        }

        private void Bind()
        {
            ds = Data.DM.ExecuteDataSet("GetImalatCikis", ProductId);
            ds.Relations.Add("rel", ds.Tables[0].Columns["GrupKodu"], ds.Tables[1].Columns["GrupKodu"]);
            BindingSource bs = new BindingSource(ds, ds.Tables[0].TableName);
            BindingSource bsDetail = new BindingSource(bs, "rel");
            gvIhtiyac.Init(bs);
            gvHammadde.Init(bsDetail);
            gvIhtiyac.BestFitColumns();
            gvHammadde.BestFitColumns();
        }

        private void btnCikis_Click(object sender, EventArgs e)
        {
            gvHammadde.EndEditing();
            DataTable dtChanges = ds.Tables[1].GetChanges();
            if (dtChanges != null)
            {
                string xml = dtChanges.SerializeChanges();
                Data.DM.ExecuteNonQuery("InsImalatCikis", xml, AppSession.UserInfo.UserId);
                Bind();
            }
        }
    }
}